package java1;

import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Fivefour {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		TreeMap<String,TreeSet<Integer>> treemap = new TreeMap<String,TreeSet<Integer>>();
		int count = 1;
		ArrayList<String> arraylist = new ArrayList<String>();
		while (sc.hasNextLine()){
			String str = sc.nextLine();
			if(str.equals("!!!!!")){	break;
			
			}
			String[] words=str.split(" ");
			arraylist.add(str);
			Scanner input = new Scanner(str);
			while(input.hasNext()){
				String string=input.next();
				if(treemap.containsKey(string)){
					treemap.get(string).add(count);
				}
				else{
					TreeSet<Integer> treeset = new TreeSet<Integer>();
					treeset.add(count);
					treemap.put(string, treeset);
				}
			}
			input.close();
			count++;
		}
		for(Entry<String, TreeSet<Integer>> entry : treemap.entrySet()){
			System.out.println(entry.getKey()+"="+entry.getValue());
		}
		while(sc.hasNextLine()){
			String str=sc.nextLine();
			Scanner input = new Scanner(str);
			if(str.length()==0){
				System.out.println("found 0 results");
				continue;
			}
			TreeSet<Integer> treeset = treemap.get(input.next());
			if(treeset==null){
				System.out.println("found 0 results");
				continue;
			}
			else if(treeset.isEmpty()){
				System.out.println("found 0 results");
				break;
			}
			else{
				System.out.println(treeset);
				for(Integer i : treeset){
					System.out.println("line " + i + ":" + arraylist.get(i-1));
				}
			}
			while(input.hasNext()){
				String str1 = input.next();
				treeset.retainAll(treemap.get(str1));
			}input.close();
		}sc.close();
	}

}

